package com.github.crush0.myblog.controller;

import com.github.crush0.myblog.dao.ArticleContentMapper;
import com.github.crush0.myblog.dao.ArticleInfoMapper;
import com.github.crush0.myblog.dao.ArticleMessageMapper;
import com.github.crush0.myblog.dao.ArticleSortMapper;
import com.github.crush0.myblog.entity.ArticleInfo;
import com.github.crush0.myblog.entity.ArticleSort;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("api/article")
public class ArticleController extends BaseController {
    private ArticleContentMapper articleContentMapper;
    private ArticleInfoMapper articleInfoMapper;
    private ArticleMessageMapper articleMessageMapper;
    private ArticleSortMapper articleSortMapper;

    @Autowired
    public ArticleController(ArticleContentMapper articleContentMapper
            ,ArticleInfoMapper articleInfoMapper
            ,ArticleMessageMapper articleMessageMapper
            ,ArticleSortMapper articleSortMapper){
        this.articleContentMapper = articleContentMapper;
        this.articleInfoMapper = articleInfoMapper;
        this.articleMessageMapper = articleMessageMapper;
        this.articleSortMapper = articleSortMapper;
    }

    @ApiOperation("新增一片文章")
    @PostMapping("/{article}")
    @ApiImplicitParam(name="article",value = "文章",required = true,dataType = "ArticleInfo")
    public String newArticle(@PathVariable ArticleInfo article){
        return "success";
    }

    @ApiOperation("获得所有文章")
    @GetMapping("/list")
    public List<ArticleInfo> articleList(){
        return articleInfoMapper.selectAll();
    }

    @ApiOperation("获得某分类所有文章")
    @PostMapping("/list/sort/{id}")
    @ApiImplicitParam(name="id",value = "分类id",required = true,dataType = "Long")
    public List<ArticleInfo> newArticle(@PathVariable Long id){
        List<ArticleSort> articleSorts = articleSortMapper.selectBySortId(id);
        List<ArticleInfo> articleInfos = new ArrayList<>();
        articleSorts.forEach(
                item->{
                    articleInfos.add(articleInfoMapper.selectByPrimaryKey(item.getArticle_id()));
                }
        );
        return articleInfos;
    }

    @ApiOperation("获得文章题图")
    @GetMapping("/picture/{id}")
    @ApiImplicitParam(name="id",value = "文章id",required = true,dataType = "Long")
    public String getArticlePic(@PathVariable Long id){
        return null;
    }

    @ApiOperation("修改文章题图")
    @PutMapping("/picture/{id}")
    @ApiImplicitParam(name="id",value = "文章id",required = true,dataType = "Long")
    public String updateArticlePic(@PathVariable Long id){
        return null;
    }

    @ApiOperation("给文章新增题图")
    @PostMapping("/picture/{id}")
    @ApiImplicitParam(name="id",value = "文章id",required = true,dataType = "Long")
    public String insertArticlePic(@PathVariable Long id,Object content){
        return null;
    }

    @ApiOperation("修改文章分类")
    @PostMapping("/sort/{id}")
    @ApiImplicitParam(name="id",value = "文章id",required = true,dataType = "Long")
    public String updateArticleSort(@PathVariable Long id,Long sortId){
        return null;
    }

    @ApiOperation("删除文章")
    @DeleteMapping("/article/{id}")
    @ApiImplicitParam(name="id",value = "文章id",required = true,dataType = "Long")
    public String deleteArticle(@PathVariable Long id){
        return null;
    }

    @ApiOperation("通过文章id获得文章内容")
    @GetMapping("/article/{id}")
    @ApiImplicitParam(name="id",value = "文章id",required = true,dataType = "Long")
    public String getArticleByID(@PathVariable Long id){
        return null;
    }

    @ApiOperation("更新文章")
    @PutMapping("/article/{id}")
    @ApiImplicitParam(name="id",value = "文章id",required = true,dataType = "Long")
    public String updateArticle(@PathVariable Long id){
        return null;
    }
}
